package com.lc.soft.controller;

import com.lc.soft.entity.CommonParameter;
import com.lc.soft.entity.DeviceEntity;
import com.lc.soft.service.IDeviceService;
import com.lc.soft.utils.ResponseResult;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("device")
@Log4j2
public class DeviceController {

    private IDeviceService deviceService;

    @Autowired
    public DeviceController(IDeviceService deviceService) {
        this.deviceService = deviceService;
    }

    @RequestMapping("create")
    public ResponseResult create(DeviceEntity deviceEntity) {
        Long start = new Date().getTime();
        ResponseResult responseResult = deviceService.create(deviceEntity);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("update")
    public ResponseResult updateMap(DeviceEntity deviceEntity) {
        Long start = new Date().getTime();
        ResponseResult responseResult = deviceService.update(deviceEntity);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("updateState")
    public ResponseResult updateState(DeviceEntity deviceEntity) {
        Long start = new Date().getTime();
        ResponseResult responseResult = deviceService.updateState(deviceEntity);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("findDeviceListByCondition")
    public ResponseResult findDeviceListByCondition(CommonParameter commonParameter) {
        Long start = new Date().getTime();
        ResponseResult responseResult = deviceService.findDeviceListByCondition(commonParameter);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("findPagedDeviceListByCondition")
    public ResponseResult findPagedDeviceListByCondition(CommonParameter commonParameter) {
        Long start = new Date().getTime();
        ResponseResult responseResult = deviceService.findPagedDeviceListByCondition(commonParameter);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }
}
